//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.dao.wills;

import com.aidong.model.wills.MemberContract;
import com.aidong.model.wills.MemberInfo;
import com.aidong.model.wills.PayList;
import com.aidong.model.wills.PtContract;
import com.aidong.model.wills.WorkflowDetail01;
import com.aidong.model.wills.WorkflowDetail02;
import com.aidong.model.wills.WorkflowDetail03;
import com.aidong.model.wills.WorkflowDetail04;
import com.aidong.model.wills.WorkflowDetail05;
import com.aidong.model.wills.WorkflowDetail06;
import com.aidong.model.wills.WorkflowDetail07;
import com.aidong.model.wills.WorkflowDetail08;
import com.aidong.model.wills.WorkflowDetail09;
import com.aidong.model.wills.WorkflowDetail10;
import com.aidong.model.wills.WorkflowDetail11;
import com.aidong.model.wills.WorkflowDetail12;
import com.aidong.model.wills.WorkflowDetail13;
import com.aidong.model.wills.WorkflowDetail14;
import com.aidong.model.wills.WorkflowDetail15;
import com.aidong.model.wills.WorkflowDetail16;
import com.aidong.model.wills.WorkflowDetail17;
import com.aidong.model.wills.WorkflowDetail18;
import com.aidong.model.wills.WorkflowDetail19;
import com.aidong.model.wills.WorkflowDetail20;
import com.aidong.model.wills.WorkflowDetail21;
import com.aidong.model.wills.WorkflowDetail22;
import com.aidong.model.wills.WorkflowDetail23;
import com.aidong.model.wills.WorkflowDetail24;
import com.aidong.model.wills.WorkflowDetail25;
import com.aidong.model.wills.WorkflowDetail26;
import com.aidong.model.wills.WorkflowDetail27;
import com.aidong.model.wills.WorkflowDetail28;
import com.aidong.model.wills.WorkflowDetail29;
import com.aidong.model.wills.WorkflowDetail30;
import com.aidong.model.wills.WorkflowDetail31;
import com.aidong.model.wills.WorkflowDetail32;
import com.aidong.model.wills.WorkflowDetail33;
import com.aidong.model.wills.WorkflowDetail34;
import com.aidong.model.wills.WorkflowDetail35;
import com.aidong.model.wills.WorkflowList;

import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;

import org.springframework.stereotype.Repository;

@Repository
public class WorkflowListDao extends BaseDao<WorkflowList, Integer> {
    public WorkflowListDao() {
    }

    public Object getWorkflowDetail(Integer workflowId, String typeId) {
        try {
            return this.getSession().get(Class.forName("com.aidong.model.wills.WorkflowDetail" + typeId), workflowId);
        } catch (Exception var4) {
            return null;
        }
    }

    public boolean chkWorkflowNotProc(String typeId, String contractCode, String[] extProp) {
        String sql = " and (status=0 or (status=1 and procResult1=0) or (status=2 and procResult2=0) or (status=3 and procResult3=0))";
        boolean num = false;
        int num1;
        if (extProp != null) {
            sql = "select count(*) from WorkflowList l inner join WorkflowDetail" + typeId + " d on l.workflowId=d.workflowId\n" + "where typeId=:p1 and l.contractCode=:p2 and d." + extProp[0] + "=:p3" + sql;
            num1 = ((Integer) this.getBySql(Integer.class, sql, new Object[]{typeId, contractCode, extProp[1]})).intValue();
        } else {
            if ("01".equals(typeId)) {
                sql = "select count(*) from WorkflowList where typeId=:p1 and memberCode=:p2" + sql;
            } else {
                sql = "select count(*) from WorkflowList where typeId=:p1 and contractCode=:p2" + sql;
            }

            num1 = ((Integer) this.getBySql(Integer.class, sql, new Object[]{typeId, contractCode})).intValue();
        }

        return num1 > 0;
    }

    public boolean chkWorkflowNotProc33(String idType, String idNumber) {
        String sql = "select count(*) from WorkflowList l inner join WorkflowDetail33 d on l.workflowId=d.workflowId\nwhere typeId=:p1 and d.idType=:p2 and d.idNumber=:p3 and (l.status=0 or (l.status=1 and procResult1=0) or (l.status=2 and procResult2=0) or (l.status=3 and procResult3=0))";
        int num = ((Integer) this.getBySql(Integer.class, sql, new Object[]{Integer.valueOf(33), idType, idNumber})).intValue();
        return num > 0;
    }

    public void addWorkflow(WorkflowList workflow, Object detail) {
        this.add(workflow);

        try {
            Method e = detail.getClass().getMethod("setWorkflowId", new Class[]{Integer.class});
            e.invoke(detail, new Object[]{workflow.getWorkflowId()});
        } catch (Exception var4) {
        }

        this.getSession().save(detail);
    }

    public void updateNote(int workflowId, String note, boolean submit) {
        String sql = "update WorkflowList set note=:p1, updateTime=getdate() where workflowId=:p2";
        this.updateBySql(sql, new Object[]{note, Integer.valueOf(workflowId)});
        if (submit) {
            sql = "update WorkflowList set submitTime=getdate() where workflowId=:p1";
            this.updateBySql(sql, new Object[]{Integer.valueOf(workflowId)});
            this.updateStatus(workflowId, 1);
        }

    }

    public void updateCancel(int workflowId) {
        String sql = "update WorkflowList set status=:p1, updateTime=getdate() where workflowId=:p2";
        this.updateBySql(sql, new Object[]{Integer.valueOf(9), Integer.valueOf(workflowId)});
    }

    public void updateProcResult(int workflowId, int status, boolean audit, String note, String userCode) {
        String sql = "update WorkflowList set procResult" + status + "=:p1, procNote" + status + "=:p2, procUser" + status + "=:p3, procTime" + status + "=getdate() where workflowId=:p4";
        this.updateBySql(sql, new Object[]{Integer.valueOf(audit ? 1 : 2), note, userCode, Integer.valueOf(workflowId)});
        if (audit) {
            this.updateStatus(workflowId, status + 1);
        }

    }

    private void updateStatus(int workflowId, int status) {
        if (status == 4) {
            this.updateFinish(workflowId);
        } else {
            String sql = "select NeedAudit" + status + " from WorkflowType where code = (select typeId from WorkflowList where workflowId=:p1)";
            Integer needAudit = (Integer) this.getBySql(Integer.class, sql, new Object[]{Integer.valueOf(workflowId)});
            boolean noAduit = needAudit != null && needAudit.intValue() == 0;
            sql = "update WorkflowList set status=:p1, procResult" + status + "=:p2 where workflowId=:p3";
            this.updateBySql(sql, new Object[]{Integer.valueOf(status), Integer.valueOf(noAduit ? -1 : 0), Integer.valueOf(workflowId)});
            if (noAduit) {
                this.updateStatus(workflowId, status + 1);
            }

        }
    }

    private void updateFinish(int workflowId) {
        String sql = "select typeId from WorkflowList where workflowId=:p1";
        String typeId = (String) this.getBySql(String.class, sql, new Object[]{Integer.valueOf(workflowId)});
        if (typeId != null) {
            if (!"20".equals(typeId) && !"22".equals(typeId)) {
                Object workflowDetail = this.getWorkflowDetail(Integer.valueOf(workflowId), typeId);
                if (workflowDetail != null) {
                    MemberInfo var21;
                    if ("01".equals(typeId)) {
                        WorkflowDetail01 var43 = (WorkflowDetail01) workflowDetail;
                        var21 = (MemberInfo) this.getSession().get(MemberInfo.class, var43.getMemberCode());
                        if (var21 != null) {
                            if (var43.getMemberPhoto() == null || var43.getMemberPhoto().length() == 0) {
                                var43.setMemberPhoto(var21.getMemberPhoto());
                            }

                            if (var43.getIdCardPhoto() == null || var43.getIdCardPhoto().length() == 0) {
                                var43.setIdCardPhoto(var21.getIdCardPhoto());
                            }
                        }

                        sql = "update MemberInfo set ChName=:p1, EnName=:p2, Gender=:p3, Mobile=:p4, IdType=:p5, IdNumber=:p6, Birthday=:p7, Country=:p8, Phone=:p9, Email=:p10, Address=:p11, Note=:p12, MemberPhoto=:p13, IdCardPhoto=:p14, updateTime=getdate() where memberCode=:p15";
                        this.updateBySql(sql, new Object[]{var43.getChName(), var43.getEnName(), var43.getGender(), var43.getMobile(), var43.getIdType(), var43.getIdNumber(), var43.getBirthday(), var43.getCountry(), var43.getPhone(), var43.getEmail(), var43.getAddress(), var43.getNote(), var43.getMemberPhoto(), var43.getIdCardPhoto(), var43.getMemberCode()});
                    } else if ("35".equals(typeId)) {
                        WorkflowDetail35 var42 = (WorkflowDetail35) workflowDetail;
                        var21 = (MemberInfo) this.getSession().get(MemberInfo.class, var42.getMemberCode());
                        if (var21 != null) {
                            if (var42.getMemberPhoto() == null || var42.getMemberPhoto().length() == 0) {
                                var42.setMemberPhoto(var21.getMemberPhoto());
                            }

                            if (var42.getIdCardPhoto() == null || var42.getIdCardPhoto().length() == 0) {
                                var42.setIdCardPhoto(var21.getIdCardPhoto());
                            }
                        }

                        sql = "update MemberInfo set ChName=:p1, EnName=:p2, Gender=:p3, Mobile=:p4, IdType=:p5, IdNumber=:p6, Birthday=:p7, Country=:p8, Phone=:p9, Email=:p10, Address=:p11, Note=:p12, MemberPhoto=:p13, IdCardPhoto=:p14, updateTime=getdate() where memberCode=:p15";
                        this.updateBySql(sql, new Object[]{var42.getChName(), var42.getEnName(), var42.getGender(), var42.getMobile(), var42.getIdType(), var42.getIdNumber(), var42.getBirthday(), var42.getCountry(), var42.getPhone(), var42.getEmail(), var42.getAddress(), var42.getNote(), var42.getMemberPhoto(), var42.getIdCardPhoto(), var42.getMemberCode()});
                    } else if ("02".equals(typeId)) {
                        WorkflowDetail02 var41 = (WorkflowDetail02) workflowDetail;
                        sql = "update PtContract set endTime=:p1, updateTime=getdate() where contractCode=:p2";
                        this.updateBySql(sql, new Object[]{var41.getDeferDate(), var41.getContractCode()});
                    } else if ("03".equals(typeId)) {
                        WorkflowDetail03 var40 = (WorkflowDetail03) workflowDetail;
                        sql = "update MemberEarnest set overDueDate=convert(datetime,convert(varchar(10),getdate()))+30,overDueUse=1, earnestDelay=1, updateTime=getdate() where saleId=:p1";
                        this.updateBySql(sql, new Object[]{var40.getEarnestId()});
                    } else {
                        String var16;
                        if ("04".equals(typeId)) {
                            WorkflowDetail04 var39 = (WorkflowDetail04) workflowDetail;
                            sql = "select isnull(procUser3,isnull(procUser2,procUser1)) from WorkflowList where workflowId=:p1";
                            var16 = (String) this.getBySql(String.class, sql, new Object[]{Integer.valueOf(workflowId)});
                            sql = "update MemberContract set status=1, approveUser=:p1, approveTime=getdate() where contractCode=:p2";
                            this.updateBySql(sql, new Object[]{var16, var39.getContractCode()});
                            sql = "update ContractSign set status=1 where contractCode=:p1 and contractType=:p2";
                            this.updateBySql(sql, new Object[]{var39.getContractCode(), "01"});
                        } else if ("05".equals(typeId)) {
                            WorkflowDetail05 var38 = (WorkflowDetail05) workflowDetail;
                            sql = "update PtContract set beginTime=:p1, endTime=:p2, updateTime=getdate() where contractCode=:p3";
                            this.updateBySql(sql, new Object[]{var38.getBeginDate(), var38.getEndDate(), var38.getContractCode()});
                        } else if ("06".equals(typeId)) {
                            WorkflowDetail06 var37 = (WorkflowDetail06) workflowDetail;
                            var16 = (String) this.getBySql(String.class, "select createUser from WorkflowList where workflowId=:p1", new Object[]{Integer.valueOf(workflowId)});
                            sql = "update PtBespeak set status=0, canceType=:p1, cancelUser=:p2, printLabel=0, cancelTime=getdate() where autoId=:p3";
                            this.updateBySql(sql, new Object[]{"2", var16, var37.getPtBespeakId()});
                            sql = "update PtContract set bespeakQuantity=(select count(*) from PtBespeak where PtBespeak.contractCode=PtContract.contractCode and status>0), clearQuantity=(select count(*) from PtBespeak where PtBespeak.contractCode=PtContract.contractCode and status=1), updateTime=getdate() where contractCode=:p1";
                            this.updateBySql(sql, new Object[]{var37.getContractCode()});
                        } else if ("07".equals(typeId)) {
                            WorkflowDetail07 var36 = (WorkflowDetail07) workflowDetail;
                            sql = "update PtContract set quantity=:p1, updateTime=getdate() where contractCode=:p2";
                            this.updateBySql(sql, new Object[]{var36.getQuantity(), var36.getContractCode()});
                        } else if ("08".equals(typeId)) {
                            WorkflowDetail08 var35 = (WorkflowDetail08) workflowDetail;
                            sql = "update MemberContract set totalCount=:p1, restCount=restCount+:p2, updateTime=getdate() where contractCode=:p3";
                            this.updateBySql(sql, new Object[]{var35.getQuantity(), Integer.valueOf(var35.getQuantity().intValue() - var35.getOldQuantity().intValue()), var35.getContractCode()});
                        } else if ("09".equals(typeId)) {
                            WorkflowDetail09 var34 = (WorkflowDetail09) workflowDetail;
                            sql = "update MemberContract set beginTime=:p1, endTime=:p2, updateTime=getdate() where contractCode=:p3";
                            this.updateBySql(sql, new Object[]{var34.getBeginDate(), var34.getEndDate(), var34.getContractCode()});
                        } else if ("10".equals(typeId)) {
                            WorkflowDetail10 var33 = (WorkflowDetail10) workflowDetail;
                            sql = "update MemberContract set cardType=:p1, updateTime=getdate() where contractCode=:p2";
                            this.updateBySql(sql, new Object[]{var33.getCardType(), var33.getContractCode()});
                        } else if ("11".equals(typeId)) {
                            WorkflowDetail11 var32 = (WorkflowDetail11) workflowDetail;
                            sql = "update MemberContract set manyShop=:p1, updateTime=getdate() where contractCode=:p2";
                            this.updateBySql(sql, new Object[]{var32.getManyShop(), var32.getContractCode()});
                        } else if ("12".equals(typeId)) {
                            WorkflowDetail12 var31 = (WorkflowDetail12) workflowDetail;
                            sql = "update MemberContract set newEndTime=:p1, updateTime=getdate() where contractCode=:p2";
                            this.updateBySql(sql, new Object[]{var31.getNewEndTime(), var31.getContractCode()});
                        } else if ("13".equals(typeId)) {
                            WorkflowDetail13 var30 = (WorkflowDetail13) workflowDetail;
                            sql = "insert into ContractShop (ContractCode, ShopCode) values(:p1,:p2)";
                            this.updateBySql(sql, new Object[]{var30.getContractCode(), var30.getAddShopCode()});
                        } else if ("14".equals(typeId)) {
                            WorkflowDetail14 var29 = (WorkflowDetail14) workflowDetail;
                            sql = "update MemberContract set effectiveType=:p1, effectiveDate=getdate() where contractCode=:p2";
                            this.updateBySql(sql, new Object[]{"W", var29.getContractCode()});
                        } else if ("15".equals(typeId)) {
                            WorkflowDetail15 var28 = (WorkflowDetail15) workflowDetail;
                            sql = "select shopCode, contractCode, memberCode, ptCode, coachCode, quantity, bespeakQuantity from PtContract where contractCode=:p1";
                            PtContract var17 = (PtContract) this.getBySql(PtContract.class, sql, new Object[]{var28.getContractCode()});
                            if (var17 == null || var28.getQuantity().intValue() > var17.getQuantity().intValue() - var17.getBespeakQuantity().intValue()) {
                                return;
                            }

                            String userCode1 = (String) this.getBySql(String.class, "select createUser from WorkflowList where workflowId=:p1", new Object[]{Integer.valueOf(workflowId)});
                            sql = "update PtContract set bespeakQuantity=bespeakQuantity+:p1, clearQuantity=clearQuantity+:p2, lastClearTime=getdate(), updateTime=getdate() where contractCode=:p3";
                            this.updateBySql(sql, new Object[]{var28.getQuantity(), var28.getQuantity(), var28.getContractCode()});

                            for (int i = 0; i < var28.getQuantity().intValue(); ++i) {
                                sql = "insert into PtBespeak (ShopCode, ContractCode, MemberCode, BespeakDate, BespeakType, PtCode, CoachCode, ClassTime, Status, PrintLabel, PrintTime, PrintUser, ClearTime, ClearUser, CreateUser, CreateTime, UpdateTime) values (:p1,:p2,:p3,:p4,:p5,:p6,:p7,:p8,:p9,:p10,:p11,:p12,:p13,:p14,:p15,getdate(),getdate())";
                                this.updateBySql(sql, new Object[]{var17.getShopCode(), var17.getContractCode(), var17.getMemberCode(), var28.getClassTime(), "1", var17.getPtCode(), var28.getCoachCode(), var28.getClassTime(), Integer.valueOf(1), Integer.valueOf(1), var28.getClassTime(), userCode1, var28.getClassTime(), userCode1, userCode1});
                            }
                        } else if ("16".equals(typeId)) {
                            WorkflowDetail16 detail = (WorkflowDetail16) workflowDetail;
                            sql = "update PayList set payType=:p1, updateTime=getdate() where autoId=:p2";
                            this.updateBySql(sql, new Object[]{detail.getPayType(), detail.getPayListId()});
                        } else if ("17".equals(typeId)) {
                            WorkflowDetail17 var9 = (WorkflowDetail17) workflowDetail;
                            sql = "update PayList set payType=:p1, updateTime=getdate() where autoId=:p2";
                            this.updateBySql(sql, new Object[]{var9.getPayType(), var9.getPayListId()});
                        } else {
                            Integer userCode;
                            if ("18".equals(typeId)) {
                                WorkflowDetail18 var10 = (WorkflowDetail18) workflowDetail;
                                sql = "select saleId from PtContract where contractCode=:p1";
                                userCode = (Integer) this.getBySql(Integer.class, sql, new Object[]{var10.getContractCode()});
                                if (userCode == null) {
                                    return;
                                }

                                sql = "update PtContract set salesCode=:p1, updateTime=getdate() where contractCode=:p2";
                                this.updateBySql(sql, new Object[]{var10.getSalesCode(), var10.getContractCode()});
                                sql = "update PayList set salesCode=:p1, updateTime=getdate() where saleId=:p2 and saleType=:p3";
                                this.updateBySql(sql, new Object[]{var10.getSalesCode(), userCode, "02"});
                            } else if ("19".equals(typeId)) {
                                WorkflowDetail19 var11 = (WorkflowDetail19) workflowDetail;
                                sql = "select saleId from PtContract where contractCode=:p1";
                                userCode = (Integer) this.getBySql(Integer.class, sql, new Object[]{var11.getContractCode()});
                                if (userCode == null) {
                                    return;
                                }

                                sql = "update PtContract set salesCode2=:p1, updateTime=getdate() where contractCode=:p2";
                                this.updateBySql(sql, new Object[]{var11.getSalesCode(), var11.getContractCode()});
                                sql = "update PayList set salesCode2=:p1, updateTime=getdate() where saleId=:p2 and saleType=:p3";
                                this.updateBySql(sql, new Object[]{var11.getSalesCode(), userCode, "02"});
                            } else if ("21".equals(typeId)) {
                                WorkflowDetail21 var12 = (WorkflowDetail21) workflowDetail;
                                sql = "update PtContract set commissionDate=:p1, updateTime=getdate() where contractCode=:p2";
                                this.updateBySql(sql, new Object[]{var12.getCommissionDate(), var12.getContractCode()});
                            } else if ("23".equals(typeId)) {
                                WorkflowDetail23 var13 = (WorkflowDetail23) workflowDetail;
                                sql = "select saleId from MemberContract where contractCode=:p1";
                                userCode = (Integer) this.getBySql(Integer.class, sql, new Object[]{var13.getContractCode()});
                                if (userCode == null) {
                                    return;
                                }

                                sql = "update MemberContract set salesCode=:p1, updateTime=getdate() where contractCode=:p2";
                                this.updateBySql(sql, new Object[]{var13.getSalesCode(), var13.getContractCode()});
                                sql = "update PayList set salesCode=:p1, updateTime=getdate() where saleId=:p2 and saleType=:p3";
                                this.updateBySql(sql, new Object[]{var13.getSalesCode(), userCode, "01"});
                            } else if ("24".equals(typeId)) {
                                WorkflowDetail24 var14 = (WorkflowDetail24) workflowDetail;
                                sql = "select saleId from MemberContract where contractCode=:p1";
                                userCode = (Integer) this.getBySql(Integer.class, sql, new Object[]{var14.getContractCode()});
                                if (userCode == null) {
                                    return;
                                }

                                sql = "update MemberContract set salesCode2=:p1, updateTime=getdate() where contractCode=:p2";
                                this.updateBySql(sql, new Object[]{var14.getSalesCode(), var14.getContractCode()});
                                sql = "update PayList set salesCode2=:p1, updateTime=getdate() where saleId=:p2 and saleType=:p3";
                                this.updateBySql(sql, new Object[]{var14.getSalesCode(), userCode, "01"});
                            } else if ("25".equals(typeId)) {
                                WorkflowDetail25 var15 = (WorkflowDetail25) workflowDetail;
                                sql = "update PayList set payType=:p1, updateTime=getdate() where autoId=:p2";
                                this.updateBySql(sql, new Object[]{var15.getPayType(), var15.getPayListId()});
                            } else if ("26".equals(typeId)) {
                                WorkflowDetail26 var18 = (WorkflowDetail26) workflowDetail;
                                sql = "update PayList set payType=:p1, updateTime=getdate() where autoId=:p2";
                                this.updateBySql(sql, new Object[]{var18.getPayType(), var18.getPayListId()});
                            } else if ("27".equals(typeId)) {
                                WorkflowDetail27 var19 = (WorkflowDetail27) workflowDetail;
                                sql = "update PayList set payType=:p1, updateTime=getdate() where autoId=:p2";
                                this.updateBySql(sql, new Object[]{var19.getPayType(), var19.getPayListId()});
                            } else if ("28".equals(typeId)) {
                                WorkflowDetail28 var20 = (WorkflowDetail28) workflowDetail;
                                sql = "update PayList set payType=:p1, updateTime=getdate() where autoId=:p2";
                                this.updateBySql(sql, new Object[]{var20.getPayType(), var20.getPayListId()});
                            } else if ("29".equals(typeId)) {
                                WorkflowDetail29 var22 = (WorkflowDetail29) workflowDetail;
                                sql = "update PayList set payType=:p1, updateTime=getdate() where autoId=:p2";
                                this.updateBySql(sql, new Object[]{var22.getPayType(), var22.getPayListId()});
                            } else if ("30".equals(typeId)) {
                                WorkflowDetail30 var23 = (WorkflowDetail30) workflowDetail;
                                sql = "update MemberContract set stopFee=:p1, changeFee=:p2, mendFee=:p3, chgShopFee=:p4, updateTime=getdate() where contractCode=:p5";
                                this.updateBySql(sql, new Object[]{var23.getStopFee(), var23.getChangeFee(), var23.getMendFee(), var23.getChgShopFee(), var23.getContractCode()});
                            } else if ("31".equals(typeId)) {
                                WorkflowDetail31 var24 = (WorkflowDetail31) workflowDetail;
                                sql = "update MemberContract set commissionDate=:p1, updateTime=getdate() where contractCode=:p2";
                                this.updateBySql(sql, new Object[]{var24.getCommissionDate(), var24.getContractCode()});
                            } else if ("32".equals(typeId)) {
                                WorkflowDetail32 var25 = (WorkflowDetail32) workflowDetail;
                                sql = "update PayList set payType=:p1, updateTime=getdate() where autoId=:p2";
                                this.updateBySql(sql, new Object[]{var25.getPayType(), var25.getPayListId()});
                            } else if ("33".equals(typeId)) {
                                WorkflowDetail33 var26 = (WorkflowDetail33) workflowDetail;
                                sql = "update MemberBlackList set status=:p1, approve=0, updateTime=getdate() where idType=:p2 and idNumber=:p3";
                                this.updateBySql(sql, new Object[]{var26.getStatus(), var26.getIdType(), var26.getIdNumber()});
                            } else {
                                if (!"34".equals(typeId)) {
                                    return;
                                }

                                WorkflowDetail34 var27 = (WorkflowDetail34) workflowDetail;
                                sql = "update MemberContract set giftCardCode=:p1, giftCardType=:p2, giftCardAmount=:p3, updateTime=getdate() where contractCode=:p4";
                                this.updateBySql(sql, new Object[]{var27.getGiftCardCode(), var27.getGiftCardType(), var27.getGiftCardAmount(), var27.getContractCode()});
                                var16 = (String) this.getBySql(String.class, "select createUser from WorkflowList where workflowId=:p1", new Object[]{Integer.valueOf(workflowId)});
                                sql = "update GiftCard set status=2, receiveUser=:p1, receiveDate=getdate() where cardCode=:p2";
                                this.updateBySql(sql, new Object[]{var16, var27.getGiftCardCode()});
                            }
                        }
                    }

                    sql = "update WorkflowList set status=:p1 where workflowId=:p2";
                    this.updateBySql(sql, new Object[]{Integer.valueOf(4), Integer.valueOf(workflowId)});
                }
            }
        }
    }

    public void addMemberContractAdjust(WorkflowDetail20 detail, List<PayList> payList, MemberContract newContract) {
        String shopCode = newContract.getShopCode();
        String sql = "select max(contractCode) from MemberContract where shopCode=:p1 and contractCode like :p2";
        String maxCode = (String) this.getBySql(String.class, sql, new Object[]{shopCode, shopCode + "%"});
        int maxId = 0;
        if (maxCode != null && maxCode.length() > shopCode.length()) {
            try {
                maxId = Integer.parseInt(maxCode.substring(shopCode.length()));
            } catch (Exception var11) {
                ;
            }
        }

        String contractCode = "000000" + (maxId + 1);
        contractCode = shopCode + contractCode.substring(contractCode.length() - 6);
        newContract.setContractCode(contractCode);
        this.getSession().save(newContract);
        Iterator i$ = payList.iterator();

        while (i$.hasNext()) {
            PayList pay = (PayList) i$.next();
            pay.setSaleId(newContract.getSaleId());
            pay.setContractCode(contractCode);
            this.getSession().save(pay);
        }

        detail.setAdjContractCode(contractCode);
        detail.setPaid(Integer.valueOf(1));
        this.getSession().update(detail);
        sql = "update WorkflowList set status=:p1 where workflowId=:p2";
        this.updateBySql(sql, new Object[]{Integer.valueOf(4), detail.getWorkflowId()});
    }

    public void addPtContractAdjust(WorkflowDetail22 detail, List<PayList> payList, PtContract newContract) {
        String shopCode = newContract.getShopCode();
        String sql = "select max(contractCode) from PtContract where shopCode=:p1 and contractCode like :p2";
        String maxCode = (String) this.getBySql(String.class, sql, new Object[]{shopCode, shopCode + "%"});
        int maxId = 0;
        if (maxCode != null && maxCode.length() > shopCode.length()) {
            try {
                maxId = Integer.parseInt(maxCode.substring(shopCode.length()));
            } catch (Exception var11) {
                ;
            }
        }

        String contractCode = "000000" + (maxId + 1);
        contractCode = shopCode + contractCode.substring(contractCode.length() - 6);
        newContract.setContractCode(contractCode);
        this.getSession().save(newContract);
        Iterator i$ = payList.iterator();

        while (i$.hasNext()) {
            PayList pay = (PayList) i$.next();
            pay.setSaleId(newContract.getSaleId());
            pay.setContractCode(contractCode);
            this.getSession().save(pay);
        }

        detail.setAdjContractCode(contractCode);
        detail.setPaid(Integer.valueOf(1));
        this.getSession().update(detail);
        sql = "update WorkflowList set status=:p1 where workflowId=:p2";
        this.updateBySql(sql, new Object[]{Integer.valueOf(4), detail.getWorkflowId()});
    }
}
